package cn.jzq.demo.web;

import cn.jzq.demo.entity.GeneralClass;
import cn.jzq.demo.service.IGeneralClassService;
import cn.jzq.demo.util.R;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/class")
public class GeneralClassController {

    @Autowired
    private IGeneralClassService classService;

    @ApiOperation(value = "get class")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "path")
    @GetMapping("/{id}")
    @Cacheable(value = "class_info", key = "#id + '_class'")
    public GeneralClass getClassById(@PathVariable Integer id) {
        return classService.selectById(id);
    }

    @ApiOperation(value = "get class 2")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "path")
    @GetMapping("/test/{id}")
    public R getClassById2(@PathVariable Integer id) {
        return R.ok().put("data", classService.getById(id));
    }
}
